/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pv168.reminder.swing.workers;

import cz.muni.fi.pv168.reminder.entities.Worker;
import cz.muni.fi.pv168.reminder.managers.WorkerManager;
import cz.muni.fi.pv168.reminder.managers.implementation.WorkerManagerImpl;
import cz.muni.fi.pv168.reminder.swing.DialogMainWorker;
import javax.swing.SwingWorker;

/**
 *
 * @author Katarína
 */
public class AddWorkerSwingWorker extends SwingWorker<Class<Void>, Void> {

    private final Worker worker;
    DialogMainWorker.TableWorkerModel model;

    public AddWorkerSwingWorker(Worker worker, DialogMainWorker.TableWorkerModel model) {
        this.worker = worker;
        this.model = model;
    }

    @Override
    protected Class<Void> doInBackground() throws Exception {
        WorkerManager workerManager = new WorkerManagerImpl();
        workerManager.setDataSource(DialogMainWorker.getDataSource());
        workerManager.createPerson(worker);
        return Void.TYPE;
    }

    @Override
    protected void done() {
        super.done();
        model.reload();
    }
}
